home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / renegade.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  147 lines

  1. /***************************************************************************
  2.  
  3.     Renegade Video Hardware
  4.  
  5. ***************************************************************************/
  6.  
  7. #include "driver.h"
  8. #include "vidhrdw/generic.h"
  9.  
  10. unsigned char *renegade_textram;
  11. int renegade_scrollx;
  12. static struct tilemap *bg_tilemap;
  13. static struct tilemap *fg_tilemap;
  14. static int flipscreen;
  15.  
  16. WRITE_HANDLER( renegade_videoram_w )
  17. {
  18.     if( videoram[offset]!=data )
  19.     {
  20.         videoram[offset] = data;
  21.         offset = offset%(64*16);
  22.         tilemap_mark_tile_dirty(bg_tilemap,offset);
  23.     }
  24. }
  25.  
  26. WRITE_HANDLER( renegade_textram_w )
  27. {
  28.     if( renegade_textram[offset]!=data )
  29.     {
  30.         renegade_textram[offset] = data;
  31.         offset = offset%(32*32);
  32.         tilemap_mark_tile_dirty(fg_tilemap,offset);
  33.     }
  34. }
  35.  
  36. WRITE_HANDLER( renegade_flipscreen_w )
  37. {
  38.     flipscreen = !data;
  39.     tilemap_set_flip( ALL_TILEMAPS, flipscreen?(TILEMAP_FLIPY|TILEMAP_FLIPX):0);
  40. }
  41.  
  42. WRITE_HANDLER( renegade_scroll0_w )
  43. {
  44.     renegade_scrollx = (renegade_scrollx&0xff00)|data;
  45. }
  46.  
  47. WRITE_HANDLER( renegade_scroll1_w )
  48. {
  49.     renegade_scrollx = (renegade_scrollx&0xFF)|(data<<8);
  50. }
  51.  
  52. static void get_bg_tilemap_info(int tile_index)
  53. {
  54.     const UINT8 *source = &videoram[tile_index];
  55.     UINT8 attributes = source[0x400]; /* CCC??BBB */
  56.     SET_TILE_INFO(
  57.         1+(attributes&0x7), /* bank */
  58.         source[0],  /* tile_number */
  59.         attributes>>5 /* color */
  60.     )
  61. }
  62.  
  63. static void get_fg_tilemap_info(int tile_index)
  64. {
  65.     const UINT8 *source = &renegade_textram[tile_index];
  66.     UINT8 attributes = source[0x400];
  67.     SET_TILE_INFO(
  68.         0,
  69.         (attributes&3)*256 + source[0], /* tile_number */
  70.         attributes>>6
  71.     )
  72. }
  73.  
  74. int renegade_vh_start( void )
  75. {
  76.     bg_tilemap = tilemap_create(get_bg_tilemap_info,tilemap_scan_rows,TILEMAP_OPAQUE,   16,16,64,16);
  77.     fg_tilemap = tilemap_create(get_fg_tilemap_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  78.  
  79.     if (!bg_tilemap || !fg_tilemap)
  80.         return 1;
  81.  
  82.     fg_tilemap->transparent_pen = 0;
  83.     tilemap_set_scrolldx( bg_tilemap, 256, 0 );
  84.  
  85.     tilemap_set_scrolldy( fg_tilemap, 0, 16 );
  86.     tilemap_set_scrolldy( bg_tilemap, 0, 16 );
  87.     return 0;
  88. }
  89.  
  90. static void draw_sprites( struct osd_bitmap *bitmap )
  91. {
  92.     const struct rectangle *clip = &Machine->drv->visible_area;
  93.  
  94.     unsigned char *source = spriteram;
  95.     unsigned char *finish = source+96*4;
  96.  
  97.     while( source<finish )
  98.     {
  99.         int sy = 240-source[0];
  100.         if( sy>=16 )
  101.         {
  102.             int attributes = source[1]; /* SFCCBBBB */
  103.             int sx = source[3];
  104.             int sprite_number = source[2];
  105.             int sprite_bank = 9 + (attributes&0xF);
  106.             int color = (attributes>>4)&0x3;
  107.             int xflip = attributes&0x40;
  108.  
  109.             if( sx>248 ) sx -= 256;
  110.  
  111.             if( attributes&0x80 ){ /* big sprite */
  112.                 drawgfx(bitmap,Machine->gfx[sprite_bank],
  113.                     sprite_number+1,
  114.                     color,
  115.                     xflip,0,
  116.                     sx,sy+16,
  117.                     clip,TRANSPARENCY_PEN,0);
  118.             }
  119.             else
  120.             {
  121.                 sy += 16;
  122.             }
  123.             drawgfx(bitmap,Machine->gfx[sprite_bank],
  124.                 sprite_number,
  125.                 color,
  126.                 xflip,0,
  127.                 sx,sy,
  128.                 clip,TRANSPARENCY_PEN,0);
  129.         }
  130.         source+=4;
  131.     }
  132. }
  133.  
  134. void renegade_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh )
  135. {
  136.     tilemap_set_scrollx( bg_tilemap, 0, renegade_scrollx );
  137.     tilemap_set_scrolly( bg_tilemap, 0, 0 );
  138.     tilemap_set_scrolly( fg_tilemap, 0, 0 );
  139.  
  140.     tilemap_update( ALL_TILEMAPS );
  141.     if (palette_recalc())  tilemap_mark_all_pixels_dirty( ALL_TILEMAPS );
  142.     tilemap_render( ALL_TILEMAPS );
  143.     tilemap_draw( bitmap,bg_tilemap,0 );
  144.     draw_sprites( bitmap );
  145.     tilemap_draw( bitmap,fg_tilemap,0 );
  146. }
  147.